<%@page pageEncoding="UTF-8" contentType="text/html; charset=UTF-8"%><!DOCTYPE HTML>
<%-- <%@include file="edit.jsp"%> --%>
<html>
<head>
<script type="text/javascript">
//选择的文章的id
var userId =${userId};
$(function(){
	$('#tag_treegrid').treegrid({
		url:'/tag/info/treeByTagType',
		singleSelect:true,
		rownumbers:true,
		striped:true,
		fitColumns:true,
		fit:true,
		idField:'id',
		treeField:'tagName',
		queryParams:{tagType:'3'},
		columns:[[
			{field:'ck',checkbox:true},
			{field:'tagName',title:'标签名称'},
		]],
		onSelect:loadSelect
	 });
	$('#tag_select').datagrid({
		singleSelect:true,
		fitColumns:true,
		fit:true,
		columns:[[
			{field:'ck',checkbox:true},
			{field:'tagName',title:'标签名称'},
			{field:'action',title:'操作',formatter:function(v,r,i){
				return '<a href="#" onclick="removeRow('+i+');">移除</a>';
			}}
		]],
	 });
});

 var loadSelect = function(row){
	 $('#tag_select').datagrid('insertRow',{
			index: 0,	// index start with 0
			row:row
		});
 }
 function removeRow(index){
	 console.log(index);
	 $('#tag_select').datagrid('deleteRow',index);
 }
 //
 function saveTag(){
	 var rows = $('#tag_select').datagrid('getRows');
	 var params = [];
	 for(var i=0;i<rows.length;i++){
		var row = rows[i];
		params[params.length]={name:'tagReUsers['+i+'].userId',value:userId};
		params[params.length]={name:'tagReUsers['+i+'].tagId',value:row.id};
	 }
	$.post('addTagRes',params,function(r){
		if(r.code<0)return top.$alert(r.msg);
		top.$window.close(window,1,null);
		top.$ok('文章标签保存成功！');
	},'json');
 }
</script>
<body>
	<div class="easyui-layout" style="width:100%;height:350px;">
		<div data-options="region:'center',title:'标签信息',iconCls:'icon-ok'">
			<table id="tag_treegrid"></table>
		</div>
		<div data-options="region:'east',split:true,title:'选中标签',collapsible:false" style="width:250px;">
			<table id="tag_select" class="easyui-datagrid"
					data-options="singleSelect:true">
			</table>
		</div>
		<div data-options="region:'south',split:true," style="height:45px;text-align:right;padding: 5px;">
			<a href="#" class="easyui-linkbutton" data-options="iconCls:'icon-ok'" onclick="saveTag()">保存</a>
		</div>
	</div>
</body>
</html>